package viroyal.com.base.adapter;

import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suntiago.baseui.utils.SPUtils;

import java.util.List;

import viroyal.com.base.R;
import viroyal.com.base.net.entity.Timetables;


/**
 * @author chenjunwei
 * @desc 当天课表
 * @date 2019/4/29
 */
public class ItemClassAdapter extends BaseItemDraggableAdapter<Timetables> {
  private int selectPos = -1;
  private String type = "1";

  public void setSelectPos(int selectPos) {
    if (this.selectPos == selectPos) {
      return;
    }
    this.selectPos = selectPos;
  }

  public ItemClassAdapter(List data) {
    super(getLayout(),data);
  }

  private static int getLayout() {
    if (android.os.Build.MODEL.equals("T2") || android.os.Build.MODEL.equals("T3") || android.os.Build.MODEL.equals("T6")) {
      //新班牌(华瑞安)
      return R.layout.item_class;
    } else if (android.os.Build.MODEL.equals("rk3288")) {
      //广州星马(班牌)
      return R.layout.item_class_xm;
    }
    return R.layout.item_class;
  }

  @Override
  protected void convert(BaseViewHolder helper, Timetables item) {
    if (item.lesson == 0) {
      helper.setText(R.id.tv_class_lesson, "");
    } else {

      helper.setText(R.id.tv_class_lesson, item.lesson + "");
    }
    if (item.starttime != null && item.endtime != null) {
      if (!TextUtils.isEmpty(item.starttime) && !TextUtils.isEmpty(item.endtime)) {
        helper.setText(R.id.tv_class_time, item.starttime + "～" + item.endtime);
      } else {
        helper.setText(R.id.tv_class_time, "");
      }
    } else {
      helper.setText(R.id.tv_class_time, "未知时间");
    }
    if (type.equals("1")) {
      helper.setText(R.id.tv_class_type, item.name);
    } else {
      helper.setText(R.id.tv_class_type, item.className);
    }

    helper.setText(R.id.tv_class_teacher, item.teathername);
    int position = helper.getLayoutPosition();
    if (position % 2 == 0) {
      helper.setBackgroundColor(R.id.data_layout, mContext.getResources().getColor(R.color.dry_data_color));
    } else {
      helper.setBackgroundColor(R.id.data_layout, mContext.getResources().getColor(R.color.dry_data_color_t));
    }

    if (position == selectPos) {
      helper.setBackgroundColor(R.id.data_layout, mContext.getResources().getColor(R.color.class_select_color));
      helper.setTextColor(R.id.tv_class_lesson, mContext.getResources().getColor(R.color.c1));
      helper.setTextColor(R.id.tv_class_time, mContext.getResources().getColor(R.color.c1));
      helper.setTextColor(R.id.tv_class_type, mContext.getResources().getColor(R.color.c1));
      helper.setTextColor(R.id.tv_class_teacher, mContext.getResources().getColor(R.color.c1));
    } else {
      helper.setTextColor(R.id.tv_class_lesson, mContext.getResources().getColor(R.color.c27));
      helper.setTextColor(R.id.tv_class_time, mContext.getResources().getColor(R.color.c27));
      helper.setTextColor(R.id.tv_class_type, mContext.getResources().getColor(R.color.c27));
      helper.setTextColor(R.id.tv_class_teacher, mContext.getResources().getColor(R.color.c27));
    }
  }

  public void setType(String type) {
    this.type = type;
  }
}

